package d8_stream;

import java.util.*;
import java.util.stream.Stream;

/**
 * 2024/6/7 stream流常用方法
 */
public class StreamTest2 {
    public static void main(String[] args) {
        //1.如何获取List集合的Stream流
        List<String> name = new ArrayList<>();
        Collections.addAll(name,"张三三", "张五五", "刘敏", "张强");
        Stream<String> stream = name.stream();
        System.out.println(Arrays.toString(stream.toArray()));

        //2.如何获取Set集合的Stream流?
       Set<String> set = new HashSet<>();
       Collections.addAll(set,"六十四","张曼玉","蜘蛛精","玛德");
        set.stream().filter(s ->s.contains("德")).forEach(s-> System.out.println(s));

        //3.如何获取Map集合的Stream流
        Map<String, Double> map = new HashMap<>();
        map.put("古力娜扎",172.3);
        map.put("迪丽热巴",168.3);
        map.put("玛卡巴",173.2);
        map.put("周杰伦",180.3);

        Set<Map.Entry<String, Double>> entries = map.entrySet();
        Stream<Map.Entry<String, Double>> st = entries.stream();
        st.filter(s ->s.getKey().contains("巴")).forEach(s->System.out.println(s.getKey()+"==>"+s.getValue()));

        //4.如何获取数组的Stream流
        String[] names={"翠西","崔西","张浩"};
        Arrays.stream(names).filter(n ->n.contains("西")).forEach(n ->System.out.println(n));
    }
}
